Skip to content

fix(download): close the output file when a streamed download fails - #428

Open
rajanpanth wants to merge 1 commit into
openzim:mainfrom
rajanpanth:fix/stream-file-close
Open

rajanpanth wants to merge 1 commit into
openzim:mainfrom
rajanpanth:fix/stream-file-close

Conversation

@rajanpanth

Copy link
Copy Markdown

Summary

  • stream_file opened the destination file and closed it only after the body had been read. An error from iter_content skipped that close and left the handle open.
  • The file and the response are now closed in a finally block. A successful download into a seekable byte stream still rewinds that stream.

Test plan

  • pytest tests/download/test_download.py::test_stream_file_closes_the_file_when_the_body_fails
  • Interrupt a download to a path and confirm the destination file is not left locked

Made with Cursor

stream_file closed the file only after a successful read, so an error from the response body left the handle open.

Co-authored-by: Cursor <cursoragent@cursor.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant